//
//  NewsModel.m
//  ProjectsOne
//
//  Created by iOS开发 on 2018/7/9.
//  Copyright © 2018年 iOS开发. All rights reserved.
//

#import "NewsModel.h"
#import "NSString+Custom.h"

@implementation commentModel

- (NSString *)name {
    if (!_name) {
        _name = @"赵薇";
    }
    return _name;
}

- (NSString *)time {
    if (!_time) {
        _time = @"2018-07-10 10:39";
    }
    return _time;
}

- (NSInteger)pictureNumber {
    if (!_pictureNumber) {
        _pictureNumber = (arc4random() % 3) + 1;
    }
    return _pictureNumber;
}

- (NSString *)comment {
    if (!_comment) {
        NSString *str = @"这里是评论";
        for (NSInteger i = 0; i < (arc4random() % 30); i++) {
            str = [str stringByAppendingString:@"这里是评论"];
        }
        _comment = str;
    }
    return _comment;
}

- (NSAttributedString *)attrComment {
    if (!_attrComment) {
        _attrComment = [self.comment stringWithParagraphlineSpeace:9 textColor:[UIColor colorWithHexString:@"666666"] textFont:[UIFont systemFontOfSize:16]];
    }
    return _attrComment;
}

- (NSInteger)starNumber {
    if (!_starNumber) {
        _starNumber = (arc4random() % 5) + 1;
    }
    return _starNumber;
}

- (CGFloat)commentCellHeight {
    if (!_commentCellHeight) {
        // 其余高度 + 正文高度 + 图片高度
        CGFloat textHeight = [self.comment getSpaceLabelHeightwithSpeace:9 withFont:[UIFont systemFontOfSize:16] withWidth:WIDTH - 95];
        CGFloat pictureHeight = 0;
        if (self.pictureNumber <= 3 && self.pictureNumber > 0) {
            pictureHeight = kCellSize;
        }
        _commentCellHeight = 124.0 + textHeight + pictureHeight;
    }
    return _commentCellHeight;
}

@end

@implementation NewsModel

- (NSString *)title {
    if (!_title) {
        NSString *str = @"这里是大标题";
        for (NSInteger i = 0; i < (arc4random() % 5); i++) {
            str = [str stringByAppendingString:@"这里是大标题"];
        }
        _title = str;
    }
    return _title;
}

- (NSString *)time {
    if (!_time) {
        _time = @"7-9";
    }
    return _time;
}

- (NSString *)source {
    if (!_source) {
        _source = @"来源:网络";
    }
    return _source;
}

- (NSString *)content {
    if (!_content) {
        NSString *str = @"这里是正文";
        for (NSInteger i = 0; i < (arc4random() % 30); i++) {
            str = [str stringByAppendingString:@"这里是正文"];
        }
        _content = str;
    }
    return _content;
}

- (NSString *)name {
    if (!_name) {
        _name = @"苏有朋";
    }
    return _name;
}

- (NSString *)isCollect {
    if (!_isCollect) {
        _isCollect = @"0";
    }
    return _isCollect;
}

- (NSInteger)pictureNumber {
    if (!_pictureNumber) {
        _pictureNumber = (arc4random() % 6) + 1;
    }
    return _pictureNumber;
}

- (NSAttributedString *)attrContent {
    if (!_attrContent) {
        _attrContent = [self.content stringWithParagraphlineSpeace:9 textColor:[UIColor colorWithHexString:@"666666"] textFont:[UIFont systemFontOfSize:16]];
    }
    return _attrContent;
}

- (CGFloat)cellHeight {
    if (!_cellHeight) {
        // 其余高度 + 正文高度 + 图片高度
        CGFloat textHeight = [self.content getSpaceLabelHeightwithSpeace:9 withFont:[UIFont systemFontOfSize:16] withWidth:WIDTH - 50];
        CGFloat pictureHeight = 0;
        if (self.pictureNumber <= 3 && self.pictureNumber > 0) {
            pictureHeight = kCellSize;
        } else if (self.pictureNumber > 3) {
            pictureHeight = kCellSize * 2 + 10;
        }
        _cellHeight = 140.0 + textHeight + pictureHeight;
    }
    return _cellHeight;
}

- (NSMutableArray<commentModel *> *)commentArr {
    if (!_commentArr) {
        _commentArr = [NSMutableArray array];
        for (NSInteger i = 0; i < (arc4random() % 5) + 1; i++) {
            [_commentArr addObject:[[commentModel alloc] init]];
        }
    }
    return _commentArr;
}

- (BOOL)isHaveMoreComment {
    return self.commentArr.count > 3;
}

@end
